package com.danhar.forward.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.alibaba.xxpt.gateway.shared.client.http.PostClient;
import com.danhar.forward.service.DingdingGovernmentClientService;
import com.danhar.forward.service.DingdingGovernmentUserService;
import com.danhar.forward.service.bean.DingDingBaseRsp;
import com.danhar.forward.util.ResponseEntity;
import com.danhar.forward.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author hu
 * @version 1.0
 * @date 2020/6/30/030
 */
@Service
public class DingdingGovernmentUserServiceImpl implements DingdingGovernmentUserService {

    @Autowired
    private DingdingGovernmentClientService dingdingGovernmentClientService;

    // 获取用户详情接口名
    private String userDetailServiceName = "/rpc/oauth2/dingtalk_app_user.json" ;
    @Override
    public DingDingBaseRsp getUserInfo( String authCode)  {

         String accessToken = dingdingGovernmentClientService.getAccessToken();
         if(accessToken.isEmpty()){
             //为空 无效的token  TODO
             DingDingBaseRsp  dingDingBaseRsp  =new   DingDingBaseRsp();
             dingDingBaseRsp.setSuccess("false");
             return      dingDingBaseRsp    ;
         }

        PostClient postClient = dingdingGovernmentClientService.getPostClient(userDetailServiceName);
        postClient.addParameter("access_token",accessToken) ;
        postClient.addParameter("auth_code",authCode) ;
        String result = postClient.post();

        DingDingBaseRsp dingDingBaseRsp = JSONObject.parseObject(result, DingDingBaseRsp.class);



       return    dingDingBaseRsp;




    }
}
